var username = document.getElementById("txt_username")
var password = document.getElementById("txt_password")
var rpassword = document.getElementById("txt_repassword")
var btn = document.querySelector(".btn_login")
var nickname = document.getElementById("txt_nickname")
var ddtbody = document.querySelector("tbody")
var ddword = document.querySelector(".successregister")
var newtip = document.querySelector(".new_tip div")
var ddbody = document.querySelector(".body")
ddbody.onclick = function () {
    newtip.innerHTML = '贴心提示：请勿设置与邮箱密码相同的账户登录密码或支付密码，防止不法分子窃取您的当当账户信息，<a href="http://blog.dangdang.com/?p=22276">谨防诈骗</a>！'
}
btn.onclick = async function () {
    let url = "http://127.0.0.1:8888/users/register";
    let options = {
        type: "POST",
        headers: {
            "Content-Type": "application/x-www-form-urlencoded"
        },
        data: {
            username: username.value,
            password: password.value,
            rpassword: rpassword.value,
            nickname: nickname.value
        }
    };
    $.ajax(url, options)
        .done(function (data) {
            console.log(data);
            if (data.code === 1) {
                ddtbody.innerHTML = "<div class='successregister'>恭喜注册成功</div>"
                setTimeout(function () {
                    location.href = "./ddlogin.html";
                }, 2000)
            } else {
                newtip.innerHTML = "贴心提示：注册失败，请重新输入信息"
                console.log(data.message);
            }
        })
}
//
$(function () {
    var $inputs = $("tbody input")
    $inputs.on("focus",function(){
        var next_ele = $(this).next()
        next_ele.css("display","block")
    })
    $inputs.on("blur",function(){
        var next_ele = $(this).next()
        next_ele.css("display","none")
    })
})